package com.uam.web.common.model;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.CollectionUtils;

import java.util.List;

public class SysLayerConfig {

    /** 默认展示的系统图层ID */
    private Integer defaultSysLayerId;
    /** 系统图层列表 */
    private List<SysLayer> sysLayerList;

    public Integer getDefaultSysLayerId() {
        return defaultSysLayerId;
    }

    public void setDefaultSysLayerId(Integer defaultSysLayerId) {
        this.defaultSysLayerId = defaultSysLayerId;
    }

    public List<SysLayer> getSysLayerList() {
        return sysLayerList;
    }

    public void setSysLayerList(List<SysLayer> sysLayerList) {
        this.sysLayerList = sysLayerList;
    }

    public SysLayer getSysLayerById(Integer id) {
        if (CollectionUtils.isEmpty(sysLayerList)) {
            return null;
        }
        for (SysLayer sysLayer : sysLayerList) {
            if (sysLayer.getId().equals(id)) {
                return sysLayer;
            }
            if (!CollectionUtils.isEmpty(sysLayer.getChildList())) {
                for (SysLayer child : sysLayer.getChildList()) {
                    if (child.getId().equals(id)) {
                        return child;
                    }
                }
            }
        }
        return null;
    }

    @ApiModel(value = "系统图层")
    public static class SysLayer {
        @ApiModelProperty(value = "系统图层ID")
        private Integer id;
        @ApiModelProperty(value = "系统图层类型")
        private Integer type;
        @ApiModelProperty(value = "系统图层名称")
        private String name;
        @ApiModelProperty(value = "系统图层资源地址", hidden = true)
        private String path;
        @ApiModelProperty(value = "系统图层子树")
        private List<SysLayer> childList;
        @ApiModelProperty(value = "系统图层内容")
        private Object content;

        public Object getContent() {
            return content;
        }

        public void setContent(Object content) {
            this.content = content;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public Integer getType() {
            return type;
        }

        public void setType(Integer type) {
            this.type = type;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getPath() {
            return path;
        }

        public void setPath(String path) {
            this.path = path;
        }

        public List<SysLayer> getChildList() {
            return childList;
        }

        public void setChildList(List<SysLayer> childList) {
            this.childList = childList;
        }
    }
}
